package com.catal.framework.sequence;

import java.io.Serializable;

/**
 * 序列号<p>
 * 
 * 属性:
 * <ul>
 * <li>noid 序列号的唯一标识</li>
 * <li>noname 序列号名称</li>
 * <li>nolength 序列号整数部分长度</li>
 * <li>notype 序列号复位类型默认不复位,1: 不复位 2: 按年复位 3: 按月复位 4: 按日复位</li>
 * <li>prefix 前缀</li>
 * <li>postfix 后缀</li>
 * <li>bufferSize 缓存大小,默认0</li>
 * </ul>
 * 
 * <pre>
 * 如某序列号的prefix="CN",postfix="_files",nolength=5
 * 则生成的序列号为 CN00001_files,CN00002_files,CN00003_files等
 * 
 * prefix与postfix可以使用{yyyy}(四位年份),{yy}(两位年份),{mm}(月份),{dd}(日期)等符号,
 * 分别表示当前年份，月份与日期
 * 
 * 如某序列号的prefix="NO{yyyymmdd}",nolength=5,notype=4,
 * 则第一天生成的序号NO2010010100001...NO2010010100005,序列号明细{year=2010,month=1,day=1,nextId=00006}
 * 第二天生成的序号NO2010010200001...NO2010010200002,序列号明细{year=2010,month=1,day=2,nextId=00003}
 * </pre>
 */
public class No implements Cloneable, Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7166614248898685221L;

	/**
	 * 默认序列号长度10
	 */
	private static final int DEFAULT_LENGTH = 10;
	
	/**
	 * 序列号的唯一标识
	 */
	private java.lang.String noid;

	/**
	 * 序列号名称
	 */
	private java.lang.String noname;

	/**
	 * 序列号整数部分长度
	 */
	private int nolength;

	/**
	 * 序列号复位类型默认不复位,1: 不复位 2: 按年复位 3: 按月复位 4: 按日复位
	 */
	private int notype;

	/**
	 * 前缀
	 */
	private java.lang.String prefix;

	/**
	 * 后缀
	 */
	private java.lang.String postfix;

	/**
	 * 缓存大小
	 */
	private int bufferSize = 0;

	public No() {
	}

	public No(String noid) {
		this(noid, null, DEFAULT_LENGTH, 1, null, null, 0);
	}

	public No(String noid, int nolength, int notype, String prefix,
			String postfix) {
		this(noid, null, nolength, notype, prefix, postfix, 0);
	}

	public No(String noid, String noname, int nolength, int notype,
			String prefix, String postfix, int bufferSize) {
		this.noid = noid;
		this.noname = noname;
		this.nolength = nolength;
		this.notype = notype;
		this.prefix = prefix;
		this.postfix = postfix;
		this.bufferSize = bufferSize;
	}

	public java.lang.String getNoid() {
		return noid;
	}

	public java.lang.String getNoname() {
		return noname;
	}

	public int getNolength() {
		return nolength;
	}

	public int getNotype() {
		return notype;
	}

	public java.lang.String getPrefix() {
		return prefix;
	}

	public java.lang.String getPostfix() {
		return postfix;
	}

	public void setNoid(java.lang.String noid) {
		this.noid = noid;
	}

	public void setNoname(java.lang.String noname) {
		this.noname = noname;
	}

	public void setNolength(int nolength) {
		this.nolength = nolength;
	}

	public void setNotype(int notype) {
		this.notype = notype;
	}

	public void setPrefix(java.lang.String prefix) {
		this.prefix = prefix;
	}

	public void setPostfix(java.lang.String postfix) {
		this.postfix = postfix;
	}

	public Object clone() {
		Object o = null;
		try {
			o = super.clone();
		} catch (CloneNotSupportedException ex) {
			System.out.println(o);
		}
		return o;
	}

	public int getBufferSize() {
		return bufferSize;
	}

	public void setBufferSize(int bufferSize) {
		this.bufferSize = bufferSize;
	}

	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("No [noid=");
		builder.append(noid);
		builder.append(", noname=");
		builder.append(noname);
		builder.append(", nolength=");
		builder.append(nolength);
		builder.append(", notype=");
		builder.append(notype);
		builder.append(", prefix=");
		builder.append(prefix);
		builder.append(", postfix=");
		builder.append(postfix);
		builder.append(", bufferSize=");
		builder.append(bufferSize);
		builder.append("]");
		return builder.toString();
	}
}
